/**
 * Created by webhugo on 16-10-16.
 */
var sequelizex = require('sequelize-short');
var shortDataTypes = sequelizex.DataTypes;

module.exports = function (sequelize, DataTypes) {

    var User = sequelize.define('User', {
        username: shortDataTypes.String(40, false, undefined, true),
        password: shortDataTypes.String(40),
        email: shortDataTypes.String(50, false, null, true),    // email 不能空且唯一
        mobile: shortDataTypes.String(20, true, undefined, true),
        avatar: shortDataTypes.String(),//头像
        // 0 => normalUser   1=>adminer
        type: shortDataTypes.Int(0),//管理员  或  普通用户
        description: shortDataTypes.String(1000, true),
        city : shortDataTypes.String(null,true,"无"),
        sex : shortDataTypes.Int(null,true,-1),
        // 个性签名
        sign : shortDataTypes.Text(true,null)
    }, {
        associate: function (models) {
            // models.User.belongsToMany(models.Course , {through: 'UserCourse'});

            models.User.hasMany(models.Comment);
            models.Comment.belongsTo(models.User);

            models.User.hasMany(models.Post);
            models.Post.belongsTo(models.User);
        },
        instanceMethods: {}
    });

    return User;
};
